<extend name="template:common" />
<block name='js'>
    <!--引入ueditor插件-->
    <script src="__UEDITOR__/ueditor.config.js"></script>
    <script src="__UEDITOR__/ueditor.all.min.js"></script>
    <script src="__UEDITOR__/lang/zh-cn/zh-cn.js"></script>
     <script>var ue = UE.getEditor('editor');</script>
     <!--ztree插件-->
     <script src="__ZTREE__/js/jquery.ztree.core.js"></script>
     <!--引入uploadify-->
    <script src="__UPLOADIFY__/jquery.uploadify.js"></script>
      <!--引入layer-->
    <script src="__LAYER__/layer.js"></script>
     <script>
        $(function(){
            $('#namex').focus(function(){
                $val = $('#namex').val();
            }).blur(function(){
                if($('#namex').val()==''){
                    $('#namex').val($val);
                }
            });
            
            /**
             * 商品状态的回显
             */
            
             $(':input[name=is_on_sale]').val([{$row.is_on_sale|default=1}]);
            //2.回显商品状态
            $('.goods_status').val({$row.goods_status});
            
        

            var setting = {
                data: {
                    simpleData: {
                        enable: true,
                        pIdKey:'parent_id',
                    }
                },
                callback:{
                    onClick:function(event,treeId,treeNode,clickFlag){
                        $('#goods_category_name').val(treeNode.name);
                        $('#goods_category_id').val(treeNode.id);
                    },
                    
                    //当触发点击事件后判断是否是叶子节点
                    beforeClick:function(treeId,treeNode){
                        if(treeNode.isParent){
                            layer.msg('选择错误',{icon:5,time:1000});
                            return false;
                        }
                    }
                }
            };

            $(document).ready(function(){
                var zNodes = {$jsondata};
               var ztree_obj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                ztree_obj.expandAll(true);
                 //1.根据父级节点的id找到ztree中对应的节点
                var category_node = ztree_obj.getNodesByParam("id", {$row.goods_category_id|default=0});
                //2.选中此节点
                if(category_node.length>0){
                    category_node = category_node[0];
                    ztree_obj.selectNode(category_node);
                    //找到父级分类的名字和id放到指定的表单控件中
                    $('#goods_category_name').val(category_node.name);
                    $('#goods_category_id').val(category_node.id);
                }

                //编辑显示父节点
              var parent_node = ztree_obj.getNodeByParam("id", {$row.parent_id|default=0});
                  //判断是否有父节点,默认选中该节点
//                      //把名字和id填到对应的input
                       ztree_obj.selectNode(parent_node);
                       $('#goods_category_name').val(tree_node.name);
                        $('#goods_category_id').val(tree_node.id);
            });
            
           
           //=====================uploadfiy上传========================
           $('#file_upload').uploadify({
                'fileObjName':'file',
                'buttonText':'选择文件',
                'swf'      : '__UPLOADIFY__/uploadify.swf',
                'uploader' : "{:U('Upload/upload')}",
                'onUploadSuccess':function(file,data){
                    //转换成json对象
                   data = $.parseJSON(data);

                    if(data.status==1){
                        var upload_img_box = $('.upload-img-box');
                        var html = '';
                        html += '<div class="upload-pre-item">';
                        html += '<input type="hidden" name="path[]" value="'+data.imgurl+'"/>';
                        html += '<img src="__SVN__/'+data.imgurl+'?imageView2/1/w/200/q/75"/>';
                        html += '<a href="javascript:void(0);">×</a>';
                        html += '</div>';
                        $(html).appendTo(upload_img_box);
                        layer.msg('上传成功',{icon:6});
                    }else{
                        layer.msg('上传失败,原因是:'+data.msg,{icon:5})
                    }
                }
            });
            
            
            //=======================logo上传===========================
                 $('#log_upload').uploadify({
                'fileObjName':'file',
                'buttonText':'选择文件',
                'swf'      : '__UPLOADIFY__/uploadify.swf',
                'uploader' : "{:U('Upload/upload')}",
                'onUploadSuccess':function(file,data){
                    //转换成json对象
                   data = $.parseJSON(data);

                    if(data.status==1){
                        var upload_log_box = $('.upload-log-box');
                        var html = '';
                        html += '<div class="upload-pre-item">';
                        html += '<input type="hidden" name="logo" value="'+data.imgurl+'"/>';
                        html += '<img src="__SVN__/'+data.imgurl+'?imageView2/1/w/200/q/75"/>';
                        html += '</div>';
                        $(html).appendTo(upload_log_box);
                        layer.msg('上传成功',{icon:6});
                    }else{
                        layer.msg('上传失败,原因是:'+data.msg,{icon:5})
                    }
                }
            });
            
        //================点击删除图片======================
        //事件绑定,当点击×的时候将div整个移除
        $('.upload-img-box').on('click','.upload-pre-item a',function(){
            var node = $(this);
            var gallery_id = node.attr('data');
            var flag = true;//是否要删除div
            if(gallery_id){
                var url = '{:U("GoodsGallery/delete")}';
                var data = {id:gallery_id};
                $.getJSON(url,data,function(response){
                    if(response.status){
                        node.parent().remove();
                    }
                });
            }else{
                node.parent().remove();
            }
        });
        
        });
    </script>
        <block name='css'>
            <!--uploadfiy样式-->
            <css href="__UPLOADIFY__/uploadify.css" />
           <css href="__ZTREE__/css/zTreeStyle/zTreeStyle.css" />
    <style>
        ul.ztree {
            margin-top: 10px;
            border: 1px solid #617775;
            background: #f0f6e4;
            width: 220px;
            overflow-y: scroll;
            overflow-x: auto;
        }
        
        .upload-pre-item img{
            width:110px;
        }

        .upload-pre-item{
            display:inline-block;
        }

        .upload-pre-item a{
            position:initial;
            top:5px;
            right:1080px;
            float:right;
            color:red;
            font-size:16px;
            text-decoration:none;
        }
        
    </style>
    </block>
</block>
<block name="main">
<h1>
    <span class="action-span"><a href="">商品列表</a>
    </span>
    <span class="action-span1"><a href="{:U('index')}">ECSHOP 管理中心</a></span>
    <span id="search_id" class="action-span1"> - 编辑商品 </span>
    <div style="clear:both"></div>
</h1>

<div class="tab-div">
    <div id="tabbody-div">
        <form enctype="multipart/form-data" action="{:U()}" method="post">
            <table width="90%" id="general-table" align="center">
                <tr>
                    <td class="label">商品名称：</td>
                    <td><input type="text" name="name" value="{$row['name']}" size="30" />
                    <span class="require-field">*</span></td>
                </tr>
                 <tr>
                    <td class="label">商品logo：</td>
                    <td>
                        <div class="upload-log-box">
                        <input type="file" id="log_upload" />
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="label">商品货号： </td>
                    <td>
                        <input type="text" name="sn" value="{$row['sn']}" size="20"/>
                        <span id="goods_sn_notice"></span><br />
                        <span class="notice-span"id="noticeGoodsSN">如果您不输入商品货号，系统将自动生成一个唯一的货号。</span>
                    </td>
                </tr>
                <tr>
                    <td class="label">商品分类：</td>
                    <td>
                        <input type="hidden" name='goods_category_id' id='goods_category_id'/>
                            <input type="text" id='goods_category_name' disabled='disabled'/>
                            <ul id="treeDemo" class="ztree"></ul>
                    </td>
                </tr>
                <tr>
                    <td class="label">商品品牌：</td>
                    <td>
                        {:arr2select($brand,'brand_id','id','name',$row['brand_id'])}
                    </td>
                </tr>
                <tr>
                    <td class="label">供货商：</td>
                    <td>
                        {:arr2select($Supplier,'supplier_id','id','name',$row['supplier_id'])}
                    </td>
                </tr>
                <tr>
                    <td class="label">本店售价：</td>
                    <td>
                        <input type="text" name="shop_price" value="{$row['shop_price']}" size="20"/>
                        <span class="require-field">*</span>
                    </td>
                </tr>
				<tr>
                    <td class="label">市场售价：</td>
                    <td>
                        <input type="text" name="market_price" value="{$row['market_price']}" size="20" />
                    </td>
                </tr>
                <tr>
                    <td class="label">商品数量：</td>
                    <td>
                        <input type="text" name="stock" size="8" value="{$row['stock']}"/>
                    </td>
                <tr>
                    <td class="label">加入推荐：</td>
                    <td>
                        <input type="checkbox" name="goods_status[]" value="1" class='goods_status'  /> 精品 
                        <input type="checkbox" name="goods_status[]" value="2" class='goods_status' /> 新品 
                        <input type="checkbox" name="goods_status[]" value="4" class='goods_status' /> 热销
                    </td>
                </tr>
                </tr>
                    <td class="label">是否上架：</td>
                    <td>
                        <input type="radio" name="is_on_sale" value="1" checked="true" /> 是
                        <input type="radio" name="is_on_sale" value="0" > 否
                    </td>
                </tr>
                <tr>
                    <td class="label">显示状态：</td>
                    <td>
                        显示:<input type="radio" name="status" size="5" value="1" checked="checked"/>
                        隐藏:<input type="radio" name="status" size="5" value="0"/>
                    </td>
                </tr>
                <tr>
                    <td class="label">排序：</td>
                    <td>
                       <input type="text" name="sort" size="5" value='{$row["sort"]}' />
                    </td>
                </tr>
                    <td class="label">商品详细描述：</td>
                    <td><textarea name="content" cols="40" rows="3" id='editor'>{$row.content}</textarea></td>
                </tr>
                    <td class="label">商品相册：</td>
                    <td>
					<div class="upload-img-box">
                                                <foreach name="row.paths" item='path'>
                                                    <div class="upload-pre-item">
                                                    <input type="hidden" name="path[]" value="'+data.imgurl+'"/>
                                                    <img src="__SVN__/{$path['path']}?imageView2/1/w/200/q/75"/>
                                                    <a href="javascript:void(0);">×</a>
                                                    </div>
                                </foreach>
                            </div>
                                            </foreach>		
                                            </div>
						<div>
                                                    <input type="file" id="file_upload" />
						</div>
                    </td>
                </tr>
            </table>

			
            <div class="button-div">
                <input type="hidden" name='id' value='{$row.id}'/>
                <input type="submit" value=" 确定 " class="button"/>
                <input type="reset" value=" 重置 " class="button" />
            </div>
        </form>
    </div>
</div>
</block>
